package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.Express;
import com.cskaoyan.bean.Mall;
import com.cskaoyan.bean.Order;
import com.cskaoyan.model.bo.MallBO;
import com.cskaoyan.model.vo.ExpressVO;
import com.cskaoyan.model.vo.MallVO;
import com.cskaoyan.model.vo.OrderVO;
import com.cskaoyan.model.vo.WxVO;
import com.cskaoyan.service.MallService;
import com.fasterxml.jackson.databind.ser.Serializers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import sun.reflect.generics.tree.BaseType;

@RestController
@RequestMapping("admin/config")
public class ConfigController {

    @Autowired
    MallService mallService;

    @RequestMapping(value = "mall",method = RequestMethod.GET)
    public BaseRespVo mall(){
        MallVO mallVO = mallService.selectByname();
        return BaseRespVo.ok(mallVO);
    }
    @RequestMapping(method = RequestMethod.POST,value = "mall")
    public BaseRespVo mall2(@RequestBody MallVO mall){
        int res = mallService.update_mall(mall);
        if(res == 1)
            return BaseRespVo.ok(mall);
        else{
            return BaseRespVo.fail("失败了");
        }
    }

    @RequestMapping(method = RequestMethod.GET,value = "express")
    public BaseRespVo express(){
        ExpressVO expressVO = mallService.select();
        return BaseRespVo.ok(expressVO);
    }
    @RequestMapping(method = RequestMethod.POST,value = "express")
    public BaseRespVo express2(@RequestBody ExpressVO expressVO){
        int res = mallService.update_express(expressVO);
        if(res == 1)
        return BaseRespVo.ok(expressVO);
        else{
            return BaseRespVo.fail("失败了");
        }
    }
    @RequestMapping("order")
    public BaseRespVo order(){
        OrderVO orderVO = mallService.selectorder();
        return BaseRespVo.ok(orderVO);
    }
    @RequestMapping(method = RequestMethod.POST,value = "order")
    public BaseRespVo order2(@RequestBody OrderVO orderVO){
        int res = mallService.update_order(orderVO);
        if(res == 1)
            return BaseRespVo.ok(orderVO);
        else{
            return BaseRespVo.fail("失败了");
        }
    }
    @RequestMapping(value = "wx",method = RequestMethod.GET)
    public BaseRespVo wx(){
        WxVO wxVO = mallService.selectWx();
        return BaseRespVo.ok(wxVO);
    }
    @RequestMapping(method = RequestMethod.POST,value = "wx")
    public BaseRespVo wx2(@RequestBody WxVO wxVO){
        int res = mallService.update_wx(wxVO);
        if(res == 1)
            return BaseRespVo.ok(wxVO);
        else{
            return BaseRespVo.fail("失败了");
        }
    }
}
